package com.oa.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oa.bean.WorkDiary;
import com.oa.dao.WorkDiaryDao;
import com.oa.service.WorkDiaryService;

@Service
public class WorkDiaryServiceImpl implements WorkDiaryService {
	

	@Resource
	WorkDiaryDao workDiaryDao;
	
	@Override
	public Integer addWorkDiary(WorkDiary diary) {
		// TODO Auto-generated method stub
		Integer result = workDiaryDao.insertWorkDiary(diary);
	
		return result;
	}

	@Override
	public Map<String, Object> getMyWorkDiary(Integer uid,Integer currentPage) {
		// TODO Auto-generated method stub
		Page page = PageHelper.startPage(currentPage, 2,"wdate desc");
		List<WorkDiary> list = workDiaryDao.selectMyDiary(uid);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("diaryList", list);
		map.put("mixNum", page.getPages());
		map.put("limit", 2);
		return map;
	}

	@Override
	public Map<String, Object> getDeptDiary(Integer dept_id,Integer currentPage) {
		// TODO Auto-generated method stub
		Page page = PageHelper.startPage(currentPage, 2,"wdate desc");
		List<WorkDiary> list = workDiaryDao.selectDeptDiary(dept_id);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("diaryList", list);
		map.put("mixNum", page.getPages());
		map.put("limit", 2);
		return map;
	}

	@Override
	public String replyDiary(Map<String, Object> map) {
		// TODO Auto-generated method stub
		Integer result = workDiaryDao.updateReplyDiary(map);
		if(result!=0){
			return "true";
		}
		return "false";
	}

	@Override
	public WorkDiary getDiaryById(Integer wid) {
		// TODO Auto-generated method stub
		WorkDiary diary = workDiaryDao.selectDiaryByWid(wid);
		return diary;
	}

}
